import java.util.ArrayList;
import java.util.Scanner;

public class demo3 {
    public static void main(String[] args) {
        System.out.println("请输入字符串：");
        Scanner scanner=new Scanner(System.in);
        String s=scanner.next();
        String ss=s.toLowerCase();
        ArrayList<Character> list=new ArrayList<>();
        int i=0;
        while (i<ss.length()){
            list.add(ss.charAt(i));
            i++;
        }
        System.out.println(list);//[a,b,b,a,c]

        //1、消除所有相邻且相同的元素
            int j=1;
            while (j<list.size()) {
                int left = 0, right = 1;
                while (right < list.size()) {
                    char a = list.get(left);
                    char b = list.get(right);
                    if (a == b) {
                        list.remove(a);
                        b=list.get(right-1);
                        list.remove(b);
                        //再重新来
                        left = 0;
                        right = 1;
                    }
                    left++;
                    right++;
                }
            }

        String end=list.toString();
        System.out.println(end);
    }
}
